<template>
  <div class="page">
    <div class="page-container">
      <div class="header">
        <div class="title">
          <span class="icon">
            <var-icon @click="hide" name="chevron-left" :size="24" />
          </span>
          <span class="text">修改昵称</span>
          <span class="btn">
            <span class="btn-item"></span>
            <span class="btn-item">
              <span class="save" @click="save">保存</span>
            </span>
          </span>
        </div>
      </div>
      <div class="center">
        <div class="card">
          <!-- <div class="card-center"> -->
          <var-input placeholder="输入昵称" v-model="state.userName" />
          <!-- </div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive } from "vue";
import { useStore } from "vuex";
import { updateInfo } from "@/api";
export default {
  name: "ModifyninameView",
  emits: ["showChangeName"],
  setup(props, ctx) {
    const store = useStore();
    const hide = (obj = { val: false }) => {
      ctx.emit("showChangeName", obj);
    };
    const state = reactive({
      userName: store.state.userInfo.userName,
      _id: store.state.userInfo._id,
      userId: store.state.userInfo.userId
    });

    const save = () => {
      updateInfo({
        url: "/users-api/updateInfo",
        params: {
          ...state
        },
        success: data => {
          store.dispatch("login", {
            token: localStorage.getItem("token"),
            userInfo: data.userInfo
          });
        },
        error: () => {},
        complete: () => {
          hide({ val: false });
        }
      });
    };
    return {
      save,
      state,
      hide
    };
  }
};
</script>

<style lang="scss" scoped>
.page {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgb(243, 242, 247);
  overflow-y: auto;
  z-index: 99999999999;
  .page-container {
    width: 100%;
    height: 100%;
    // background-color: rgb(255, 255, 255);
    display: flex;
    flex-direction: column;
    .header {
      width: 100%;
      height: 40px;
      line-height: 40px;
      // display: flex;
      background-color: rgb(243, 242, 247);
      .title {
        width: 100%;
        text-align: center;
        overflow: hidden;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 5px;
        position: relative;
        .btn {
          display: inline-block;
          display: flex;
          width: 80px;
          align-items: center;
          .btn-item {
            display: inline-block;
            padding: 0 10px;
            display: flex;
            justify-content: center;
            align-items: center;
          }
        }
        .icon {
          // float: left;
          width: 80px;
          height: 100%;
          line-height: 100%;
        }
        .text {
          flex: 1;
          display: flex;
          align-items: center;
          justify-content: center;
          font-weight: 500;
          // width: 100%;
          height: 100%;
          // z-index: -1;
        }
      }
      .searchBar {
        width: 100%;
        height: 30px;
        // background-color: orange;

        padding: 5px;

        .input-box {
          display: inline-block;
          width: 100%;
          height: 30px;
          border-radius: 50px;
          overflow: hidden;
          position: relative;
          .icon {
            width: 30px;
            height: 30px;
            display: inline-block;
            // background-color: orange;
            position: absolute;
          }

          input {
            display: inline-block;
            width: 100%;
            height: 100%;
            background-color: rgb(243, 242, 247);
            border: none;
            outline: none;
            padding-left: 30px;
          }
        }
      }
    }
    .center {
      padding: 5px;
      width: 100%;
      flex: 1;
      overflow-y: auto;
      .card {
        width: 100%;
        padding: 5px;
        .card-center {
          display: flex;
          background-color: white;
          width: 100%;
          height: 100%;
          border-radius: 5px;
          padding: 5px 10px;
          font-size: 14px;
          align-items: center;
          justify-content: space-between;
          color: #474747;
          .label {
            height: 50px;

            span {
              display: flex;
              height: 100%;
              align-items: center;
            }
          }
          .text {
            // width: 50px;
            height: 50px;
            overflow: hidden;
            border-radius: 5px;
            display: flex;
            align-items: center;
            span {
              color: #474747;
            }
            img {
              width: 50px;
              height: 50px;
            }
          }
        }
        .outLogin {
          height: 40px;
          line-height: 40px;
          text-align: center;
          display: flex;
          justify-content: center;
        }
      }
    }
  }
}
</style>